package com.xlhj.jpa.service.impl;

import com.xlhj.jpa.dao.SysUserDao;
import com.xlhj.jpa.entity.SysUser;
import com.xlhj.jpa.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: lcj
 * @Date: 2020/11/16 8:45
 * @Description: 业务层接口实现类
 * @Version: 0.0.1
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserDao userDao;

    @Override
    public SysUser insertUser(SysUser user) {
        return userDao.save(user);
    }

    @Override
    public List<SysUser> selectAllUser() {
        return userDao.findAll();
    }

    @Override
    public SysUser selectUserById(Long id) {
        return userDao.getOne(id);
    }

    @Override
    public SysUser updateUser(SysUser user) {
        SysUser exitUser = userDao.getOne(user.getId());
        exitUser.setUserCode(user.getUserCode());
        exitUser.setUserName(user.getUserName());
        exitUser.setSex(user.getSex());
        exitUser.setAge(user.getAge());
        return userDao.save(exitUser);
    }

    @Override
    public void deleteUserById(Long id) {
        userDao.deleteById(id);
    }

    @Override
    public Page<SysUser> selectUserByPage(Pageable pageable) {
        return userDao.findAll(pageable);
    }

    @Override
    public SysUser findByUserCode(String userCode) {
        return userDao.findByUserCode(userCode);
    }

    @Override
    public List<SysUser> findByUserName(String userName) {
        return userDao.findByUserName(userName);
    }

    @Override
    public Page<SysUser> findByUserNameAndPage(String userName, Pageable pageable) {
        return userDao.findByUserNameAndPage(userName, pageable);
    }
}
